define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/index' + location.search,
                    add_url: 'goods/add',
                    edit_url: 'goods/edit',
                    del_url: 'goods/del',
                    multi_url: 'goods/multi',
                    import_url: 'goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'addr', title: __('Addr'), operate: 'LIKE'},
                        {field: 'lc', title: __('Lc'), operate: 'LIKE'},
                        {field: 'siteswitch', title: __('Siteswitch'), table: table, formatter: Table.api.formatter.toggle},
                        {field: 'price', title: __('Price'), operate: 'LIKE'},
                        {field: 'size', title: __('Size'), operate: 'LIKE'},
                        {field: 'cx', title: __('Cx'), operate: 'LIKE'},
                        {field: 'rent_type', title: __('Rent_type'), operate: 'LIKE'},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'hot_switch', title: __('Hot_switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'now_status', title: __('Now_status'), searchList: {"1":__('Now_status 1'),"2":__('Now_status 2'),"3":__('Now_status 3'),"4":__('Now_status 4'),"5":__('Now_status 5'),"6":__('Now_status 6')}, formatter: Table.api.formatter.status},
                        {field: 'public_status', title: __('Public_status'), searchList: {"1":__('Public_status 1'),"2":__('Public_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'tag.title', title: __('Tag.title'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            hide_all();//隐藏全部


            $(":radio").click(function(){
                change_status();
            });

            function change_status() {
                var now = $(':radio[name="row[now_status]"]:checked').val();
                switch (now) {
                    //现房:1=现房,2=准现房,3=新房,4=商铺,5=租房,6=二手房
                    case '1':                        
                        show1();
                        break;

                    case '2':                        
                        show1();
                        break;
                    case '3':                        
                        show1();
                        break;
                    case '4':                        
                        show4();
                        break;

                    case '5':                        
                        show5();
                        break;
                    case '6':                        
                        show6();
                        break;


                    default:
                        alert('没有此选项'+now);
                        break;
                }
            };

            //隐藏全部
            function hide_all(){
                $('.form-group').hide();
                $('.now_status').show();
            }

            function show1(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');
            }



            function show4(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');
            }


            function show5(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');

                show('#c-house_years');
                show('#c-house_year');

                show('#c-rent_type');
                show('#c-de_kzf');
                show('#c-de_kt');
                show('#c-de_xyj');
                show('#c-de_furniture');
                show('#c-de_bathroom');
                show('#c-de_tv');
                show('#c-de_wifi');
            }


            function show6(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-house_years');
                show('#c-house_year');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');

                show('#c-price');
            }

            function show(v){
                if($(v).parent().attr('class')!='form-group'){
                    if($(v).parent().parent().attr('class')!='form-group'){
                        if($(v).parent().parent().parent().attr('class')!='form-group'){
                            if($(v).parent().parent().parent().parent().attr('class')!='form-group'){
                                if($(v).parent().parent().parent().parent().parent().attr('class')!='form-group'){
                               
                                    //如果还不行继续循环吧
                                    $(v).parent().parent().parent().parent().parent().parent().show();

                                }else{
                                    $(v).parent().parent().parent().parent().parent().show();
                                }


                            }else{
                                $(v).parent().parent().parent().parent().show();
                            }
                        }else{
                            $(v).parent().parent().parent().show();
                        }
                    }else{
                        $(v).parent().parent().show();
                    }
                }else{
                    $(v).parent().show();
                }
            }





        },
        edit: function () {
            Controller.api.bindevent();




            hide_all();//隐藏全部

            change_status();
            $(":radio").click(function(){
                change_status();
            });

            function change_status() {
                var now = $(':radio[name="row[now_status]"]:checked').val();
                switch (now) {
                    //现房:1=现房,2=准现房,3=新房,4=商铺,5=租房,6=二手房
                    case '1':                        
                        show1();
                        break;

                    case '2':                        
                        show1();
                        break;
                    case '3':                        
                        show1();
                        break;

                    case '4':                        
                        show4();
                        break;

                    case '5':                        
                        show5();
                        break;
                    case '6':                        
                        show6();
                        break;


                    default:
                        alert('没有此选项'+now);
                        break;
                }
            };

            //隐藏全部
            function hide_all(){
                $('.form-group').hide();
                $('.now_status').show();
            }

            function show1(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');
            }



            function show4(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');
            }


            function show5(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');
                show('#c-price');

                show('#c-house_years');
                show('#c-house_year');

                show('#c-rent_type');
                show('#c-de_kzf');
                show('#c-de_kt');
                show('#c-de_xyj');
                show('#c-de_furniture');
                show('#c-de_bathroom');
                show('#c-de_tv');
                show('#c-de_wifi');
            }


            function show6(){
                hide_all();//隐藏全部

                // show('#c-siteswitch');//状态(0:隐藏,1:显示):
                show('#c-content');
                show('#c-images');                
                show('#c-name');
                show('#c-lc');
                show('#c-cx');
                show('#c-house_type');
                show('#c-size');
                show('#c-addr');
                // show('#c-row[public_status]-1');//
                show('#c-zb_school');
                show('#c-zb_hospital');
                show('#c-zb_bus');
                show('#c-zb_sc');
                // show('#c-tag_ids');

                show('#c-house_years');
                show('#c-house_year');

                show('#c-ps');
                show('#c-province');
                show('#c-city');
                show('#c-district');

                show('#c-price');
            }

            function show(v){
                if($(v).parent().attr('class')!='form-group'){
                    if($(v).parent().parent().attr('class')!='form-group'){
                        if($(v).parent().parent().parent().attr('class')!='form-group'){
                            if($(v).parent().parent().parent().parent().attr('class')!='form-group'){
                                if($(v).parent().parent().parent().parent().parent().attr('class')!='form-group'){
                               
                                    //如果还不行继续循环吧
                                    $(v).parent().parent().parent().parent().parent().parent().show();

                                }else{
                                    $(v).parent().parent().parent().parent().parent().show();
                                }


                            }else{
                                $(v).parent().parent().parent().parent().show();
                            }
                        }else{
                            $(v).parent().parent().parent().show();
                        }
                    }else{
                        $(v).parent().parent().show();
                    }
                }else{
                    $(v).parent().show();
                }
            }

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});